package com.gitee.ywj1352.gasc.security;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.ProviderNotFoundException;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.stereotype.Component;

import java.util.Objects;

@Component
public class CusAuthenticationManager implements AuthenticationManager {

    @Autowired
    private  SSOAuthenticationProvider ssoAuthenticationProvider;

    @Override
    public Authentication authenticate(Authentication authentication) throws AuthenticationException {
        // 这里 目前 自定义在支持 sso
        Authentication result = ssoAuthenticationProvider.authenticate(authentication);
        //你还可以 继续添加 校验规则 比如  jwt token 等等
        if (Objects.nonNull(result)) {
            return result;
        }
        throw new ProviderNotFoundException("Authentication failed!");
    }
}
